// router.tsx - React Router 配置
import { createBrowserRouter, Navigate } from 'react-router-dom';
import AppLayout from './components/Layout/AppLayout';

// Pages
import Dashboard from './pages/Dashboard/Dashboard';
import ConnectionList from './pages/Connections/ConnectionList';
import ConnectionForm from './pages/Connections/ConnectionForm';
import DomainDetail from './pages/Domains/DomainDetail';
import DomainConsole from './pages/Domains/DomainConsole';
import DomainList from './pages/Domains/DomainList';
import DomainCreate from './pages/Domains/DomainCreate';
import StoragePoolList from './pages/Storage/StoragePoolList';
import VolumeList from './pages/Storage/VolumeList';
import VolumeCreate from './pages/Storage/VolumeCreate';
import NetworkList from './pages/Networks/NetworkList';
import NetworkForm from './pages/Networks/NetworkForm';
import SystemInfo from './pages/System/SystemInfo';
import NotFound from './pages/NotFound';

// 路由配置
export const router = createBrowserRouter([
  {
    path: '/',
    element: <AppLayout />,
    children: [
      {
        index: true,
        element: <Navigate to="/dashboard" replace />,
      },
      {
        path: 'dashboard',
        element: <Dashboard />,
      },
      {
        path: 'connections',
        children: [
          {
            index: true,
            element: <ConnectionList />,
          },
          {
            path: 'new',
            element: <ConnectionForm />,
          },
          {
            path: ':connectionId/edit',
            element: <ConnectionForm />,
          },
        ],
      },
      {
        path: 'domains',
        children: [
          {
            index: true,
            element: <DomainList />,
          },
          {
            path: 'new',
            element: <DomainCreate />,
          },
          {
            path: ':domainName',
            element: <DomainDetail />,
          },
          {
            path: ':domainName/console/:consoleType',
            element: <DomainConsole />,
          },
        ],
      },
      {
        path: 'storage',
        children: [
          {
            index: true,
            element: <StoragePoolList />,
          },
          {
            path: ':poolName/volumes',
            element: <VolumeList />,
          },
          {
            path: ':poolName/volumes/new',
            element: <VolumeCreate />,
          },
        ],
      },
      {
        path: 'networks',
        children: [
          {
            index: true,
            element: <NetworkList />,
          },
          {
            path: 'new',
            element: <NetworkForm />,
          },
          {
            path: ':networkName/edit',
            element: <NetworkForm />,
          },
        ],
      },
      {
        path: 'system',
        element: <SystemInfo />,
      },
      {
        path: '*',
        element: <NotFound />,
      },
    ],
  },
]);

// 路由路径常量（方便引用）
export const ROUTES = {
  DASHBOARD: '/dashboard',
  CONNECTIONS: '/connections',
  CONNECTION_NEW: '/connections/new',
  CONNECTION_EDIT: (id: string) => `/connections/${id}/edit`,
  
  DOMAINS: '/domains',
  DOMAIN_NEW: '/domains/new',
  DOMAIN_DETAIL: (name: string) => `/domains/${name}`,
  DOMAIN_CONSOLE: (name: string, type: 'vnc' | 'spice' | 'serial') => 
    `/domains/${name}/console/${type}`,
  
  STORAGE: '/storage',
  STORAGE_VOLUMES: (poolName: string) => `/storage/${poolName}/volumes`,
  VOLUME_NEW: (poolName: string) => `/storage/${poolName}/volumes/new`,
  
  NETWORKS: '/networks',
  NETWORK_NEW: '/networks/new',
  NETWORK_EDIT: (name: string) => `/networks/${name}/edit`,
  
  SYSTEM: '/system',
} as const;